package com.lifeservice.console.service.impl;

import java.rmi.ServerException;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import com.lifeservice.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lifeservice.console.mapper.LifeServiceMapper;
import com.lifeservice.console.domain.LifeService;
import com.lifeservice.console.service.ILifeServiceService;

/**
 * 便捷服务信息Service业务层处理
 * 
 * @author lifeservice
 * @date 2023-03-01
 */
@Service
public class LifeServiceServiceImpl implements ILifeServiceService 
{
    @Autowired
    private LifeServiceMapper lifeServiceMapper;

    /**
     * 查询便捷服务信息
     * 
     * @param id 便捷服务信息主键
     * @return 便捷服务信息
     */
    @Override
    public LifeService selectLifeServiceById(String id)
    {
        return lifeServiceMapper.selectLifeServiceById(id);
    }

    /**
     * 查询便捷服务信息列表
     * 
     * @param lifeService 便捷服务信息
     * @return 便捷服务信息
     */
    @Override
    public List<LifeService> selectLifeServiceList(LifeService lifeService)
    {
        return lifeServiceMapper.selectLifeServiceList(lifeService);
    }

    /**
     * 新增便捷服务信息
     * 
     * @param lifeService 便捷服务信息
     * @return 结果
     */
    @Override
    public int insertLifeService(LifeService lifeService)
    {
        lifeService.setCreateTime(DateUtils.getNowDate());
        return lifeServiceMapper.insertLifeService(lifeService);
    }

    /**
     * 修改便捷服务信息
     * 
     * @param lifeService 便捷服务信息
     * @return 结果
     */
    @Override
    public int updateLifeService(LifeService lifeService)
    {
        lifeService.setUpdateTime(DateUtils.getNowDate());
        return lifeServiceMapper.updateLifeService(lifeService);
    }

    /**
     * 批量删除便捷服务信息
     * 
     * @param ids 需要删除的便捷服务信息主键
     * @return 结果
     */
    @Override
    public int deleteLifeServiceByIds(String[] ids)
    {
        return lifeServiceMapper.deleteLifeServiceByIds(ids);
    }

    /**
     * 删除便捷服务信息信息
     * 
     * @param id 便捷服务信息主键
     * @return 结果
     */
    @Override
    public int deleteLifeServiceById(String id)
    {
        return lifeServiceMapper.deleteLifeServiceById(id);
    }

    @Override
    public int updateIsHide(LifeService lifeService) {
        //根据id获取到
        LifeService lifeServiceKu = this.selectLifeServiceById(lifeService.getId());
        if(lifeService.getIsHide().equals(lifeServiceKu.getIsHide())){
            return 1;
        }

      return  lifeServiceMapper.updateIsHide(lifeService);
    }
}
